﻿using System;
using System.IO;

namespace Ivory
{
    public sealed class IvoryLog
    {
        //Fields  
		private string _FileName; 
		public string FileName
		{
			get { return _FileName; }
			set { _FileName = value; }
		} 
		
		private bool _ShowTimeStamp; 
		public bool ShowTimeStamp
		{
		    get { return _ShowTimeStamp; }
		    set { _ShowTimeStamp = value; }
		} 
         
		private bool _OverwriteIfExists; 
		public bool OverwriteIfExists
		{
			get { return _OverwriteIfExists; }
			set { _OverwriteIfExists = value; }
		} 
		 
		private string _TimeStampFormat; 
		public string TimeStampFormat
		{
			get { return _TimeStampFormat; }
			set { _TimeStampFormat = value; }
		} 
         
		private string _InstanceName; 
		public string InstanceName
		{
			get { return _InstanceName; }
			set { _InstanceName = value; }
		} 
				
        //cTor
        public IvoryLog(string FileName, string InstanceName = "IvoryLog")
        {
            ShowTimeStamp = true;
            TimeStampFormat = "dd:mm:yy hh:mm";
            this.InstanceName = InstanceName;
            this.FileName = FileName;
        }
        public IvoryLog(string FileName, bool append, string InstanceName = "IvoryLog")
        {
            ShowTimeStamp = true;
            TimeStampFormat = "dd:mm:yy hh:mm";
            OverwriteIfExists = !append;
            this.InstanceName = InstanceName;
            this.FileName = FileName;
        }

        //Methods
        public void CreateFile()
        {
            using (StreamWriter writer = new StreamWriter(FileName, false))
            {
                Write(InstanceName + " logging started");                
            };
        }
        public void Write(object obj)
        {
            using (StreamWriter writer = new StreamWriter(FileName, !OverwriteIfExists))
            {
                string outputStr = @"[" + DateTime.Now.ToString(TimeStampFormat) + "]: ";
                outputStr += obj.ToString();

                writer.WriteLine(outputStr);
            };
        }
    }
}
